Onload indicates that all dom elements have been created, after the image and css are added, ready is triggered after the dom element is created. Therefore, jquery ready can improve the webpage response speed;
Jquery:
All along, all kinds of JS best practice will tell us that JS is placed in the end of the HTML, that is /body> , the reason is: JS will block the download, and, in JS is likely to have the operation of the DOM, put in the end of the HTML, as far as possible to ensure that the execution of JS after the completion of the DOM loading. If executed in the OnLoad event, if the page has a lot of images, then the o
Therefore, the ready of jquery can improve the response speed of the Web page;
Jquery:ready's standard wording:
Copy Code code as follows:
$ (document). Ready (function () {
Alert ("Load End");
});
A $ (document) converts the document of a DOM object into a
All along, all kinds of JS best practice will tell us that JS is placed in the end of the HTML, that is /body> , the reason is: JS will block the download, and, in JS is likely to have the operation of the DOM, put in the end of the HTML, as far as possible to ensure that the execution of JS after the completion of the DOM loading. If executed in the OnLoad event, if the page has a lot of images, then the o
the inside, and finally the call of the callback add,Based on the above speculation, we found this code implementation.Call JQuery.ready.promise (), enter the function to determine whether readylist is already present, create a deferred object to readylist when it does not exist, and readylist is a deferred instance objectDown judgment document.readystate = = = "complete" If not true execute settimeout (jquery.ready); Later analyze Jquery.ready This static method that hangs on to jqueryThis is
First, preface When we use the jquery framework when developing Web projects, we may often use $ (document) in this way. Ready (FN), $ (function () {}), which is used because the browser renders the DOM tree JavaScript is not able to manipulate DOM nodes that are not rendered well.In fact, in addition to the $ (docum
JQuery $ (document). ready () and JavaScript onload events, jquery. ready
To bind element operations and events, you need to wait for a proper time. See the following example:
In this case, the event is bound before the element is loaded,The browser Console reports the following error: TypeError: document. getElementB
Several ways to handle loading time in jqueryThe first type:JQuery (document). Ready (function() {alert ("Hello");}); // or $ (document). Ready (function() {alert ("Hello");});The second type:JQuery (function() {alert ("Hello");}); // or $ (function() {alert ("Hello");});The third type:(function() {alert ("Hello");}) (jQuery); (function() {alert ("Hello");}) ($);
In jQuery, the ready function and window. onload are executed first. window. onload and ready
A. About $ (document). ready ():
$ (Document). ready () in jquery, what is the role of $ (document).
) {///Ready (TRUE), where the number of cuts is. can also replace dry ready (wait = = = = true?--jquery.readywait:jquery.isready) {return;}//Ready () when the tag Dom is loaded complete jquery.isre Ady = true; Ready (2881064151) can set IsReady, only the default 1 times if (
Header
The above formula shows that Start Render is mainly affected by the following factors (developer controllable ):
(1) Server Response Time
(2) HTML document size
(3) Head resource usageIi. Dom ready definition
DOM Ready refers to the time when page Parsing is completed. There is a corresponding
the HTML document header to finish parsing
From the above formula, you can see that start render is mainly affected by the following factors (developer controllable):
(1) Server response time
(2) Size of HTML document
(3) The use of resources in head the second, DOM ready definition
Dom ready, refers to the time the p
When the page load is done to do something: in general, the response load order of a page is: Domain name resolution-loading html-loading JS and css-loading pictures and other information.1.window.onload EventsEffect: Triggers when all the resources on the page have been loaded. A slow response to a resource such as a large picture on the page can cause the Window.onload event to delay the triggeringPrinciple: One is ready, indicating that the documen
jquery changes the order of the Ready method calls, executes the JS code after ready. Table of Contents
Problem description
Execute the above method after all the Ready methods
Overriding the $.fn.ready method
View $.fn.ready's Source definition
Modify your $.fn.ready
Closures for added sec
If you only need to manipulate the DOM, then there is no need to wait for the page to load. We need a quicker approach.
Firefox has domcontentloaded events can be easily resolved, unfortunately, ie did not.
One of MSDN's methods for JScript is obscure, when the page DOM is not loaded, an exception is generated when the DoScroll method is invoked. Then we use the reverse, if not abnormal, then the page
Test Code Snippet One: Intentionally linked to the wall, the test results are as follows:1. The 6th row blocks the 7th line, (the link tag placed before the script will block script and will not block if link is placed after the script) 2. The IMG tag in the body blocks the Window.onload event. 3. The IMG tag in the body does not block the DOM ready event. Two. Test Code Snippet 2. 1. The IMG tag in the b
This article describes in detail how to use the ready () method of jquery events and the differences between ready and load events in jQuery. For more information, see. During page initialization, more $ (document) is used ). ready (function () {// code}); or $ (window ). lo
The front-end development in order to achieve a certain purpose, often there are many ways: Dom core,html dom,jquery; Dom Core/jquery obtains property values primarily through function calls (GetAttribute ("property name")/attr ("Property name"), and the HTML
If you only need to perform operations on the DOM, there is no need to wait until all the pages are loaded. We need a faster method.Firefox has a DOMContentLoaded event that can be easily solved. Unfortunately, IE does not.MSDN's method of JSCRIPT is unremarkable. When the page DOM is not loaded, an exception occurs when the doScroll method is called. If no exception occurs, the page
Enter the URL address in the browser address bar, when the browser starts loading the page, there are several procedures1. The browser begins parsing the HTML document2. The browser encounters the Reference:Https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onloadHttps://www.w3.org/TR/html5/syntax.html#the-endJavaScript Standard Reference Tutorial http://javascript.ruanyifeng.com/dom/document.htmlThe difference between
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.